#include <vector>
#include <algorithm>
#include <gtest/gtest.h>

TEST(TestAlgorithm, copy_backward)
{
	std::cout<< "_First \n"
			 <<	"A bidirectional iterator addressing the position of the first element in the source range. \n"
			 << "_Last	\n"
			 <<	"A bidirectional iterator addressing the position that is one past the final element in the source range.\n"
			 <<	"_DestEnd	\n"
			 << "A bidirectional iterator addressing the position of the one past the final element in the destination range. \n" 
			 << std::endl;


	using namespace std;
	vector <int> v1, v2;
	vector <int>::iterator Iter1, Iter2;

	int i;
	for ( i = 0 ; i <= 5 ; i++ )
	  v1.push_back( 10 * i );

	int ii;
	for ( ii = 0 ; ii <= 10 ; ii++ )
	  v2.push_back( 3 * ii );

	cout << "v1 = ( " ;
	for ( Iter1 = v1.begin( ) ; Iter1 != v1.end( ) ; Iter1++ )
	  cout << *Iter1 << " ";
	cout << ")" << endl;

	cout << "v2 = ( " ;
	for ( Iter2 = v2.begin( ) ; Iter2 != v2.end( ) ; Iter2++ )
	  cout << *Iter2 << " ";
	cout << ")" << endl;

	// To copy_backward the first 3 elements of v1 into the middle of v2
	copy_backward( v1.begin( ), v1.begin( ) + 3, v2.begin( ) + 7 );

	cout << "v2 with v1 insert = ( " ;
	for ( Iter2 = v2.begin( ) ; Iter2 != v2.end( ) ; Iter2++ )
	  cout << *Iter2 << " ";
	cout << ")" << endl;

	// To shift the elements inserted into v2 two positions
	// to the right
	copy_backward( v2.begin( )+4, v2.begin( ) + 7, v2.begin( ) + 9 );

	cout << "v2 with shifted insert = ( " ;
	for ( Iter2 = v2.begin( ) ; Iter2 != v2.end( ) ; Iter2++ )
	  cout << *Iter2 << " ";
	cout << ")" << endl;

}